<html>
    <head>
        <title></title>
        <meta name="wechat-enable-text-zoom-em" content="true">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="color-scheme" content="light dark">
        <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0,viewport-fit=cover">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="format-detection" content="telephone=no">
        <meta name="referrer" content="origin-when-cross-origin">
        <meta name="referrer" content="strict-origin-when-cross-origin">
        <script src="https://push.baidu.com/static/js/libs/jquery-2.0.3.js"></script>
        <style>
            *{
                padding: 0;
                margin: 0;
            }
            body {
                width: 100%;
                height: 100vh;
                background: #fff;
                overflow: hidden;
            }
            .ssl_tips_container {
                display: flex;
                justify-content: center;
                padding: 15px 0;
            }
            .ssl_tips {
                display: flex;
                align-items: center;
            }
            .ssl_logo {
                width: 20px;
                margin-right: 3px;
            }
            .ssl_logo img {
                width: 16px;
                height: 16px;
                margin: 2px 2px;
            }
            .ssl_text {
                flex: 1;
                font-size: 14px;
                color: #999;
            }
            .jump_gif {
                width: 50%;
                margin: 50px auto 0;
            }
            .jump_gif img {
                width: 100%;
            }
            .jump_text {
                text-align: center;
                font-size: 16px;
                color: #666;
                margin-top: 80px;
            }
            .jump_button_tips {
                text-align: center;
                color: #ccc;
                margin-top: 10px;
                font-size: 15px;
            }
            .jump_button {
                width: 45%;
                height: 45px;
                line-height: 45px;
                text-align: center;
                color: #fff;
                background: rgb(6, 201, 100);
                border-radius: 10px;
                margin: 20px auto 0;
                font-size: 16px;
            }
            .a-jump {
                text-decoration: none;
                -webkit-tap-highlight-color:rgba(255,0,0,0);
            }
            .powerby {
                position: fixed;
                bottom: 20px;
                left: 0;
                right: 0;
                margin: 0 auto;
                color: #ccc;
                font-size: 13px;
                text-align: center;
            }
            .error {
                width: 80%;
                text-align: center;
                font-size: 14px;
                color: #666;
                margin: 50px auto 0;
            }
        </style>
    </head>
    
    <body>
        
        <!--app根节点-->
        <div id="app"></div>
        
        <script>

            // 请求路径结构如下：
            // http://或https:// + 你的域名 + 引流宝安装目录
            // ----------------------------------------------
            // 假设你的域名是 www.baidu.com 引流宝安装在根目录
            // 那么下面req_domain应该配置：https://www.baidu.com
            // ----------------------------------------------
            // 假设你的域名是 www.baidu.com 引流宝安装在二级目录，目录名为 ylb
            // 那么下面应该配置：https://www.baidu.com/ylb
            // ----------------------------------------------
            // 请注意：无需 / 结尾
            // 请注意：无需 / 结尾
            var req_domain = 'https://ylb.wxpad.cn';
            // 请注意：无需 / 结尾
            // 请注意：无需 / 结尾
            // ----------------------------------------------
        
            // 获取当前页面的完整URL
            var currentURL = window.location.href;
            var url = new URL(currentURL);
            
            // 获取jwid参数的值
            var jwid = url.searchParams.get("jwid");
            
            // 获取type参数的值
            var type = url.searchParams.get("type");
            
            // 检查是否成功获取jwid参数的值
            if (jwid) {
                
                // 通过jwid获取到详情
                const ajax_path = req_domain + '/console/plugin/app/jumpWX/server/';
                $.ajax({
                    url: ajax_path + 'getJwInfoCallback.php?jwid=' + jwid,
                    dataType: 'jsonp',
                    jsonpCallback: 'handleJSONPResponse',
                    success: function(res) {
                        
                        if(res.code == 200) {
                            
                            // 获取成功
                            // 背景图片
                            const jw_bgimg = res.jwInfo.jw_bgimg;
                            
                            // 标题
                            const jw_title = res.jwInfo.jw_title;
                            
                            // 图标
                            const jw_icon = res.jwInfo.jw_icon;
                            
                            // 摘要（备注）
                            const jw_beizhu = res.jwInfo.jw_beizhu;
                            
                            // 目标链接
                            const jw_url = res.jwInfo.jw_url;
                            
                            // 资源路径
                            const resource_path = req_domain + '/console/plugin/app/jumpWX/img/';
                            
                            // 根据type参数显示gif
                            var jump_gif;
                            switch (type) {
                                case 'douyin':
                                    jump_gif = resource_path + 'douyin-jumpwx.gif';
                                    break;
                                case 'xhs':
                                    jump_gif = resource_path + 'xhs-jumpwx.gif';
                                    break;
                                case 'weibo':
                                    jump_gif = resource_path + 'weibo-jumpwx.gif';
                                    break;
                                case 'zhihu':
                                    jump_gif = resource_path + 'zhihu-jumpwx.gif';
                                    break;
                                default:
                                    jump_gif = resource_path + 'jumpwx.gif';
                                    break;
                            }

                            // SSL_LOGO
                            var ssl_logo_img = resource_path + 'ssl_logo.png';
                            
                            // 渲染HTML
                            $('#app').html(
                                '<div class="ssl_tips_container">'+
                                '   <div class="ssl_tips">' +
                                '       <span class="ssl_logo"><img src="'+ssl_logo_img+'" /></span>' +
                                '       <span class="ssl_text">本页面已启用SSL安全加密</span>' +
                                '   </div>'+
                                '</div>' +
                                '<div class="jump_gif"><img src="'+jump_gif+'" /></div>' +
                                '<div class="jump_text">正在跳转至微信...</div>' +
                                '<div class="jump_button_tips">如没有自动跳转请点击按钮跳转</div>' +
                                '<a href="'+jw_url+'" id="'+jwid+'" onclick="clickNum(this)" class="a-jump">' +
                                '    <div class="jump_button">点击跳转</div>' +
                                '</a>' +
                                '<div class="powerby">私域引流宝提供技术支持</div>' +
                                '<iframe src="'+jw_url+'" style="opacity:0;"></iframe>'
                            );
                            
                            // 图标
                            var shortcutIconLink = $("<link>");
                            shortcutIconLink.attr("rel", "shortcut icon");
                            shortcutIconLink.attr("href", jw_icon);
                            $("head").append(shortcutIconLink);
                            
                            // 摘要
                            var metaDescLink = $('<meta>');
                            metaDescLink.attr('name', 'description');
                            metaDescLink.attr('content', jw_beizhu);
                            $('head').append(metaDescLink);

                            // 标题
                            $("title").text(jw_title);
                        }else{
                            
                            // 获取失败
                            $('#app').html('<p class="error">无法在服务器获取到数据<br>请检查当前jwid是否正确</p>');
                        }
                    },
                    error: function() {
                        
                        // 连接服务器失败
                        $('#app').html('<p class="error">连接服务器失败！<br>请检查index.html文件的域名配置是否正确</p>');
                    }
                });
                
                // 点击次数记录
                function clickNum(e) {
                    
                    const ajax_path = req_domain + '/console/plugin/app/jumpWX/server/';
                    $.ajax({
                        url: ajax_path + 'clickNumCallback.php?jwid=' + e.id,
                        dataType: 'jsonp',
                        jsonpCallback: 'handleJSONPResponse',
                        success: function(res) {
                            
                            console.log(res.msg);
                        }
                    });
                }
            }else {
                
                // 页面加载失败
                $('#app').html('<p class="error">页面加载失败！<br>链接中没有传递jwid参数</p>');
            }
            
            // 屏蔽分享
            document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
                WeixinJSBridge.call('hideOptionMenu');
            });
        </script>
    </body>
</html>